package bavaria.hightech.logging;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Formatter;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;




public class DebugHandler implements InvocationHandler  {
    private BankInterface bank;
   
    static Logger logger;
    
    
    public DebugHandler(BankInterface bank)  {
        this.bank = bank;
        logger = Logger.getLogger("LoggingA");

    }
    
    public Object invoke(Object proxy, Method method, Object[] args)  {
    
    	String string = "";
    	
    	
    	string +=("* calling method " + method + " with params ");
    	if(args != null)
    	for (int i = 0; i < args.length; i++) 
            string +=(" " + args[i]);
        string +='\n';
        

        Object result = null;
        try  {
            result = method.invoke(bank, args);
        } catch(IllegalAccessException ex)  {
            ex.printStackTrace();
        } catch(InvocationTargetException ex)  {
            logger.log(Level.SEVERE, "* exception:" + ex.getTargetException());
        }

        string +=("* result:" + result);
        logger.log(Level.FINE, string);
        return result;
    }

}
